<template>
	<view class="container">
		<!-- 空状态栏占位 -->
		<view class="status-bar"></view>
		
		<!-- 头部区域 -->
		<view class="header">
			<view class="user-info">
				<image class="avatar" src="/static/个人头像.png" @click="goToProfile"></image>
				<text class="title">备件管理</text>
			</view>
		</view>
		
		<!-- 横幅区域 -->
		<view class="banner">
			<view class="banner-bg">
				<view class="banner-image">
					<!-- 背景图片区域 -->
				</view>
				<view class="banner-text-overlay">
					<text class="banner-text">智慧维保</text>
					<text class="banner-subtitle">让报修更简单</text>
				</view>
			</view>
		</view>
		
		<!-- 主要功能按钮 -->
		<view class="main-actions">
			<view class="action-row">
				<view class="action-item" @click="goToSparePartsLedger">
					<view class="action-icon green">
						<text class="icon-text">⊞</text>
					</view>
					<text class="action-title">备件台账</text>
				</view>
				<view class="action-item" @click="goToOutboundHistory">
					<view class="action-icon red">
						<text class="icon-text">📤</text>
					</view>
					<text class="action-title">出库履历</text>
				</view>
				<view class="action-item" @click="goToInboundHistory">
					<view class="action-icon blue">
						<text class="icon-text">📥</text>
					</view>
					<text class="action-title">入库履历</text>
				</view>
				<view class="action-item" @click="goToInventoryCheck">
					<view class="action-icon green">
						<text class="icon-text">🔍</text>
					</view>
					<text class="action-title">盘点单</text>
				</view>
			</view>
		</view>
		
		<!-- 底部导航栏 -->
		<view class="bottom-nav">
			<view class="nav-item" @click="goToWorkbench">
				<text class="nav-icon">⊞</text>
				<text class="nav-text">工作台</text>
			</view>
			<view class="nav-item" @click="goToAssetManagement">
				<text class="nav-icon">📦</text>
				<text class="nav-text">资产管理</text>
			</view>
			<view class="nav-item" @click="goToFaultReport">
				<text class="nav-icon">📋</text>
				<text class="nav-text">故障报修</text>
			</view>
			<view class="nav-item" @click="goToRepairs">
				<text class="nav-icon">🔧</text>
				<text class="nav-text">故障维修</text>
				<view class="nav-badge">3</view>
			</view>
			<view class="nav-item" @click="goToMore">
				<text class="nav-icon">⋯</text>
				<text class="nav-text">更多</text>
			</view>
		</view>
	</view>
</template>

<script>
	import navigation from '@/utils/navigation.js'
	
	export default {
		components: {
		},
		data() {
			return {
				title: '备件管理'
			}
		},
		onLoad() {
			this.checkLoginStatus();
		},
		onShow() {
			this.loadUserInfo();
		},
		methods: {
			// 检查登录状态
			checkLoginStatus() {
				const token = uni.getStorageSync('token');
				if (!token) {
					uni.reLaunch({
						url: '/pages/login/login'
					});
				}
			},
			
			// 加载用户信息
			loadUserInfo() {
				const userInfo = uni.getStorageSync('userInfo');
				if (userInfo) {
					this.userInfo = userInfo;
				}
			},
			
		goToProfile() {
			uni.navigateTo({
				url: '/pages/user/profile'
			});
		},
		
		goToSparePartsLedger() {
				uni.navigateTo({
					url: '/pages/spare-parts/ledger'
				});
			},
			
			goToOutboundHistory() {
				uni.navigateTo({
					url: '/pages/spare-parts/outbound-history'
				});
			},
			
			goToInboundHistory() {
				uni.navigateTo({
					url: '/pages/spare-parts/inbound-history'
				});
			},
			
			goToInventoryCheck() {
				uni.navigateTo({
					url: '/pages/spare-parts/inventory-check'
				});
			},
			
			// 底部导航栏点击事件 - 使用智能导航
			goToWorkbench() {
				navigation.goToWorkbench();
			},
			
			goToAssetManagement() {
				navigation.goToAssetManagement();
			},
			
			goToFaultReport() {
				navigation.goToFaultReport();
			},
			
			goToFaultMaintenance() {
				navigation.goToRepairs();
			},
			
			goToMore() {
				navigation.goToMore();
			},
			
			goToRepairs() {
				navigation.goToRepairs();
			}
		}
	}
</script>

<style>
	.container {
		background-color: white;
		min-height: 100vh;
	}

	/* 状态栏占位 */
	.status-bar {
		height: var(--status-bar-height);
		width: 100%;
		background-color: white;
	}

	/* 头部区域 */
	.header {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 10px 15px;
		background-color: white;
		color: #333;
		border-bottom: 1px solid #f0f0f0;
	}

	.user-info {
		display: flex;
		align-items: center;
	}

	.avatar {
		width: 40px;
		height: 40px;
		border-radius: 50%;
		margin-right: 10px;
		background-color: #f0f0f0;
	}

	.title {
		font-size: 20px;
		font-weight: bold;
	}

	/* 横幅区域 */
	.banner {
		padding: 20px;
		background-color: white;
	}

	.banner-bg {
		background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
		border-radius: 16px;
		height: 140px;
		position: relative;
		overflow: hidden;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 0 25px;
	}

	.banner-image {
		width: 65%;
		height: 100%;
		background: linear-gradient(45deg, rgba(255,255,255,0.15) 0%, rgba(255,255,255,0.08) 100%);
		border-radius: 12px;
		position: relative;
		backdrop-filter: blur(2px);
	}

	.banner-text-overlay {
		width: 30%;
		display: flex;
		flex-direction: column;
		align-items: flex-end;
		justify-content: center;
	}

	.banner-text {
		font-size: 22px;
		font-weight: bold;
		color: white;
		margin-bottom: 8px;
		text-align: right;
		text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
	}

	.banner-subtitle {
		font-size: 15px;
		color: white;
		opacity: 0.95;
		text-align: right;
		text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
	}

	/* 主要功能按钮 */
	.main-actions {
		padding: 40px 30px;
		background-color: white;
		border-top-left-radius: 25px;
		border-top-right-radius: 25px;
		margin-top: -25px;
		position: relative;
		z-index: 1;
		box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
	}

	.action-row {
		display: flex;
		justify-content: space-around;
		align-items: center;
		gap: 10px;
	}

	.action-item {
		display: flex;
		flex-direction: column;
		align-items: center;
		position: relative;
		flex: 1;
		max-width: 90px;
	}

	.action-icon {
		width: 70px;
		height: 70px;
		border-radius: 18px;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 32px;
		margin-bottom: 12px;
		box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
		position: relative;
	}

	.action-icon.green {
		background-color: #4caf50;
	}

	.action-icon.red {
		background-color: #f44336;
	}

	.action-icon.blue {
		background-color: #2196f3;
	}

	.icon-text {
		color: white;
		font-weight: bold;
	}

	.action-badge {
		position: absolute;
		top: -10px;
		right: -10px;
		background-color: #ff4444;
		color: white;
		border-radius: 12px;
		padding: 4px 8px;
		font-size: 11px;
		font-weight: bold;
		min-width: 24px;
		text-align: center;
		box-shadow: 0 2px 8px rgba(255, 68, 68, 0.3);
	}

	.action-title {
		font-size: 14px;
		color: #333;
		font-weight: 500;
		text-align: center;
		line-height: 1.2;
	}

	/* 底部导航栏 */
	.bottom-nav {
		display: flex;
		justify-content: space-around;
		align-items: center;
		height: 80px;
		background-color: white;
		border-top: 1px solid #f0f0f0;
		position: fixed;
		bottom: 0;
		width: 100%;
		box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
		padding-bottom: 15px;
	}

	.nav-item {
		display: flex;
		flex-direction: column;
		align-items: center;
		color: #999;
		font-size: 12px;
		position: relative;
		padding: 10px 0;
	}

	.nav-item.active {
		color: #4a94ff;
	}

	.nav-icon {
		font-size: 26px;
		margin-bottom: 6px;
	}

	.nav-text {
		font-size: 12px;
		font-weight: 500;
	}

	.nav-badge {
		position: absolute;
		top: 8px;
		right: 18px;
		width: 10px;
		height: 10px;
		background-color: #ff4444;
		border-radius: 50%;
		box-shadow: 0 2px 4px rgba(255, 68, 68, 0.3);
	}
	
	/* 底部导航栏 */
	.bottom-nav {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		background-color: #ffffff;
		border-top: 1rpx solid #e0e0e0;
		display: flex;
		justify-content: space-around;
		padding: 20rpx 0;
		z-index: 9999;
		box-shadow: 0 -2rpx 8rpx rgba(0, 0, 0, 0.1);
		height: 120rpx;
	}
	
	.nav-item {
		display: flex;
		flex-direction: column;
		align-items: center;
		gap: 8rpx;
		position: relative;
		flex: 1;
		color: #999999;
		font-size: 24rpx;
		padding: 10rpx 0;
	}
	
	.nav-item.active {
		color: #007AFF;
	}
	
	.nav-item.active .nav-icon {
		color: #007AFF;
	}
	
	.nav-item.active .nav-text {
		color: #007AFF;
		font-weight: 500;
	}
	
	.nav-icon {
		font-size: 40rpx;
		margin-bottom: 5rpx;
		color: #666666;
	}
	
	.nav-text {
		font-size: 20rpx;
		color: #666666;
	}
	
	.nav-badge {
		position: absolute;
		top: 5rpx;
		right: 15rpx;
		width: 20rpx;
		height: 20rpx;
		background-color: #ff3b30;
		border-radius: 50%;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 12rpx;
		color: white;
		font-weight: bold;
		min-width: 20rpx;
		text-align: center;
		line-height: 1;
	}
</style>
